//
//  ClassifyTableViewCell.m
//  TextApplication
//
//  Created by dllo on 16/8/30.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "ClassifyTableViewCell.h"
#import "ClassifySecond.h"
#import "TextLabelTableViewCell.h"
#import "TAMacro.h"

@interface ClassifyTableViewCell ()<UITableViewDataSource, UITableViewDelegate>

@end


@implementation ClassifyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _picImageView = [[UIImageView alloc] init];
        _table_width = -350;
        [self createTableView];
    }
    return self;
}

- (void)createTableView {
    self.classifyTableView = [[UITableView alloc] init];
    self.classifyTableView = [[UITableView alloc] initWithFrame:CGRectMake(_table_width, 0, CONTENTWIDTH - 70, self.contentView.bounds.size.height) style:UITableViewStylePlain];
    self.classifyTableView.delegate = self;
    self.classifyTableView.dataSource = self;
    self.classifyTableView.backgroundColor = [UIColor blackColor];
    self.classifyTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.classifyTableView registerClass:[TextLabelTableViewCell class] forCellReuseIdentifier:@"classReuse"];
    [self.contentView addSubview:self.classifyTableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.tableArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TextLabelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"classReuse"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.label = self.tableArray[indexPath.row]; // 传model
    cell.backgroundColor = [UIColor blackColor];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    return cell;
}
// 需要利用协议传值 传id 进行拼接字符串 跳转业面
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [self.delegate sendID:self.tableArray[indexPath.row].cat_id secID:self.itemID];
}


- (void)layoutSubviews {
    [super layoutSubviews];
    _picImageView.frame = CGRectMake(0, 0, self.contentView.bounds.size.width, self.contentView.bounds.size.height);
    [self.contentView addSubview:self.picImageView];
//    NSLog(@"%f", _table_width);
    _classifyTableView.frame = CGRectMake(_table_width,0, CONTENTWIDTH - 70, self.contentView.bounds.size.height);
    _classifyTableView.backgroundColor = [UIColor blackColor];
    _classifyTableView.alpha = 0.4;
    [self.contentView addSubview:self.classifyTableView];
}

- (void)setTable_width:(CGFloat)table_width {
    _table_width = table_width;
//    [self.classifyTableView reloadData];
}

- (void)setItemID:(NSString *)itemID {
    _itemID = itemID;
    [self.classifyTableView reloadData];
}

- (void)setTableArray:(NSArray<ClassifySecond *> *)tableArray {
    _tableArray  = tableArray;
//    NSLog(@"qqqq%@", _tableArray);
    [self.classifyTableView reloadData];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
